package com.llmcu.source.javase.objectoriented.keywords.modifier;

/**
 * 测试修饰符
 *
 * @author liuling
 * @date 2024/10/6 22:58
 */
public class SomeClass {
    private String name;
    int age;
    protected String addr;
    public int height;

    private String getName() {
        return name;
    }

    int getAge() {
        return age;
    }

    protected String getAddr() {
        return addr;
    }

    public int getHeight() {
        return height;
    }

    /**
     * 同一类中可以所有类成员
     */
    class InnerClass {
        public void foo() {
            System.out.println(SomeClass.this.name);
            System.out.println(SomeClass.this.getName());
        }
    }
}

/**
 * 同一package下的类，可以访问非private所有修饰符修饰的类成员
 */
class SecondClass {
    public void foo() {
        SomeClass someClass = new SomeClass();
        System.out.println(someClass.age);
        System.out.println(someClass.getAge());
        System.out.println(someClass.addr);
        System.out.println(someClass.getAddr());
        System.out.println(someClass.height);
        System.out.println(someClass.getHeight());
    }
}
